<?php

class Content_Exception extends CMS_Exception {}
class Content_Not_Found_Exception extends Content_Exception {}

class Content {

	protected $id;
	protected $title;
	protected $body;
	protected $site;

	public function body(){
		return $this->body;
	}

	public function id(){
		return $this->id;
	}

	public function title(){
		return $this->title;
	}

	public static function GetByID($id){
		$result = Database::getInstance()->query("SELECT * from `content` WHERE `id` = %u AND `site` = %u", $id, Site::getInstance()->GetID());
		if(!($content = $result->fetch_object('Content'))){
			throw new Content_Not_Found_Exception();
		}
		return $content;
	}

	public function Update($data){
		$result = Database::getInstance()->query("UPDATE `content` SET `title` = %s, `body` = %s WHERE `id` = %u AND `site` = %u", $data['title'], $data['body'], $this->id, Site::getInstance()->GetID());
	}

}
